<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <script src="../../js/base/boot.js?id=form"></script>
</head>

<body>
<div class="mui-searchRegion">
    <div class="mui-searchRegionS">
        <header class="mui-bar mui-bar-nav mui-header-absolute">
            <a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left mui-headerA-pm"></a>
        </header>
        <div id="queryArea" class="title">
            <h1 id="mui-title" class="mui-title"></h1>
        </div>
    </div>
    <div id="buttonArea" class="buttonArea" style="display: none">
        <div class="title-btn">
        </div>
    </div>
</div>
<div class="mui-content mui-list-form showTop" style="width: 100%;padding-top: 40px;">
    <form class="mui-input-group">
        <div id='Form'>
        </div>
        <div id='hidden_area' style="display: none"></div>
    </form>
    <div id="btn_area" class="form-btn">
    </div>
</div>

</body>

<script>
    var Form;
    var FormData;
    var parmMap;
    var state;
    var WO = {};//WO对象
    var run_model = page.getUrlParam('modelflag');//运行模型
    var formCode = page.getUrlParam("formCode");
    mui.showLoading();
    mui.init({
        swipeBack: true //启用右滑关闭功能
    });

    function InitForm() {
        if (!page.isnotNull(formCode)) {
            mui.alert("表单编码formCode不能为空", '提示', '确定', null, 'div')
            return false;
        }
        initMoreBottom();
        initBar();
        var formConfig = loadFormCodfig(formCode);
        parmMap = page.getUrlParamMap();
        parmMap = initParmMap(parmMap);
        state = page.getUrlParam("formState");
        if (state == undefined) {
            state = "";
        }
        state = initFormState(state);
        Form = new FormApp({
            "layOutID": "Form",
            "buttonAreaID": "buttonArea",
            "hiddenAreaId": "hidden_area",
            "parmMap": parmMap,
            "formConfig": formConfig
        });
        FormData = Form.initialize();
        FormData = initFormData(FormData);
        mui.hideLoading();
        var state1 = "";
        if (FormData == null) {
            if (state == "") {
                state1 = "new";
            }
        } else {
            if (state == "") {
                state1 = "update";
            }
        }
        if (state) {
            Form.setConditionMode(state);
        }
        if (state1 != state) {
            Form.setConditionMode(state1);
        }
        Form.dataAutoBinding(FormData);
        var group = $(".form-group-more");
        if (group.length == 0) {
            $("#appForm").addClass("form-group-more");
        }
        setTimeout('initFormStyle()', 100);
        if (page.getUrlParam("hideTitle")) {
            $(".mui-searchRegionS").hide();
            $(".mui-content").css("padding-top", "0px")
        }
    }

    function loadFormCodfig(formCode) {
        // var url = 'system.common.queryConfig';
        // url = initQueryConfigUrl(url);
        // configJson = initConfig(configJson); // formcode
        // var formInfo = webApi.ajax(url, configJson);
        var formConfig = {};
        if (run_model != '1') {//原有逻辑
            var parm = {
                "funName": "queryFormConfigInfoByFormCodeApp",
                "funType": "c",
                "keyPath": "System/Config/FormConfig",
                "vKey": formCode,
                "valMap": {
                    "formCode": formCode
                },
                "orderBys": "sff_type,sff_index"
            };
            var formInfo = webApi.ajax("system.form.queryFormNew", parm);
            if (formInfo) {
                var msg = '';
                if (formInfo.status == "0") {
                    formConfig = formInfo.result.data;
                    if (formConfig.sff_status != '1') {
                        mui.alert("表单未启用", '提示', '确定', null, 'div')
                        return false;
                    }
                    formConfig["sff_title"] = formConfig.sff_title;
                    formConfig["csystem"] = formConfig.csystem;
                    formConfig["sff_db_name"] = formConfig.sff_db_name;
                    formConfig["sff_condition"] = formConfig.sff_condition;
                    formConfig["sff_appjs"] = formConfig.sff_appjs;
                    formConfig["sff_app_config"] = eval('(' + decodeURI(formConfig.sff_app_config) + ')');
                    if (!formConfig.sff_app_layout) {
                        $(".mui-searchRegion").remove();
                        $(".mui-list-form").css("padding-top", "1px");
                        dialogBox.alert("APP表单未配置！");
                        return;
                    }
                    if (formConfig["sff_app_config"].Controls.length == 0) {
                        $(".mui-searchRegion").remove();
                        $(".mui-list-form").css("padding-top", "1px");
                        dialogBox.alert("APP表单未配置！");
                        return;
                    }
                    $(document).attr("title", formConfig.sff_title);
                    $("#mui-title").text(formConfig.sff_title).css("text-align", "center");

                    if (page.isnotNull(formConfig["sff_appjs"])) {
                        page.loadJsOrCss(formConfig["sff_appjs"]);
                    }
                } else {
                    msg = "加载表单配置出错,表单[formCode:" + formCode + "]配置信息不存在";
                    mui.alert(msg, '提示', '确定', null, 'div')
                    return false;
                }
            } else {
                msg = "读取表单配置出错[formCode:" + formCode + "]";
                mui.alert(msg, '提示', '确定', null,
                )
                return false;
            }
        } else {
            var keyPath = "System/Config/FormJsonConfig/app";
            //根据code和类型获取content
            var codeJson = { //根据表单编码获取执行配置名称
                "funName": "queryAppFormChildList",
                "funType": "C",
                "keyPath": keyPath,
                "vKey": formCode + "|FormJsonConfig|app",
                "valMap": {
                    "SFF_CODE": formCode
                }
            }
            var configRet = webApi.ajax("system.common.queryList", codeJson);
            var sff_appjs;
            var configJson = '';
            var dataQueryJson = '';
            if (configRet && configRet.status == "0" && configRet.result && configRet.result.data) {
                for (var item = 0; item < configRet.result.data.length; item++) {
                    var data = configRet.result.data[item];
                    if (!page.isnotNull(sff_appjs)) {
                        sff_appjs = data.sff_appjs;
                    }
                    //配置查询5
                    if (data.sff_type == '10') {
                        configJson = configJson + data.sfc_content;
                    }
                    //数据配置6
                    if (data.sff_type == '11') {
                        dataQueryJson = dataQueryJson + data.sfc_content;
                    }
                }
                configJson = decodeURI(configJson);
                dataQueryJson = decodeURI(dataQueryJson);
                page.setLocalStorage(formCode + "_queryconfig", configJson);//配置查询放进缓存
                page.setLocalStorage(formCode + "_dataquery", dataQueryJson);//数据查询放进缓存
            }
            if (page.isnotNull(sff_appjs)) {
                page.loadJsOrCss(sff_appjs);
            }
            var url = 'system.common.queryConfig';
            url = initQueryConfigUrl(url);
            configJson = initConfig(configJson);
            var formInfo = webApi.ajax(url, configJson);
            if (formInfo && formInfo.status == "0") {
                page.loadJsOrCss('/js/base64.js');
                WO["configSource"] = formInfo.result.data;
                formConfig = WO["configSource"][formCode];
                if (formConfig.sff_status != '1') {
                    mui.alert("表单未启用", '提示', '确定', null, 'div')
                    return false;
                }

                formConfig["sff_title"] = formConfig.sff_title;
                formConfig["csystem"] = formConfig.csystem;
                formConfig["sff_db_name"] = formConfig.sff_db_name;
                formConfig["sff_condition"] = formConfig.sff_condition;
                formConfig["sff_js"] = formConfig.sff_js;
                formConfig["sff_app_config"] = JSON.parse(decode(formConfig["sff_app_config"]));
                if (!formConfig.sff_app_layout) {
                    $(".mui-searchRegion").remove();
                    $(".mui-list-form").css("padding-top", "1px");
                    dialogBox.alert("APP表单未配置！");
                    return;
                }
                if (formConfig["sff_app_config"].Controls.length == 0) {
                    $(".mui-searchRegion").remove();
                    $(".mui-list-form").css("padding-top", "1px");
                    dialogBox.alert("APP表单未配置！");
                    return;
                }
                $(document).attr("title", formConfig.sff_title);
                $("#mui-title").text(formConfig.sff_title).css("text-align", "center");


            } else {
                msg = "加载表单配置出错,表单[formCode:" + formCode + "]配置信息不存在";
                mui.alert(msg, '提示', '确定', null, 'div')
                return false;
            }
        }

        return formConfig;
    }

    function loadFormCodfig2(formCode) {
        var formConfig = {};
        var msg = '';
        var parm = {
            "formCode": formCode
        };
        var configJson = JSON.stringify(parm);
        var url = "bx.bill.QueryConfig";
        url = initQueryConfigUrl(url);
        configJson = initConfig(configJson);
        var formInfo = webApi.ajax(url, configJson);
        if (formInfo && formInfo.status == "0") {
            page.loadJsOrCss('/js/base64.js');
            formConfig = formInfo.result.data[formCode];

            run_model = formConfig.run_model;

            if(run_model == 0){
                formConfig["sff_app_config"] = eval('(' + decodeURI(formConfig.sff_app_config) + ')');
            }else {
                formConfig["sff_app_config"] = JSON.parse(decode(formConfig["sff_app_config"]));
                page.setLocalStorage(formCode + "_dataquery", formConfig.dataQueryJson);//数据查询放进缓存
                WO["configSource"] = formInfo.result.data;
            }
            if (formConfig.sff_status != '1') {
                mui.alert("表单未启用", '提示', '确定', null, 'div')
                return false;
            }
            if (!formConfig.sff_app_layout) {
                $(".mui-searchRegion").remove();
                $(".mui-list-form").css("padding-top", "1px");
                dialogBox.alert("APP表单未配置！");
                return;
            }
            if (formConfig["sff_app_config"].Controls.length == 0) {
                $(".mui-searchRegion").remove();
                $(".mui-list-form").css("padding-top", "1px");
                dialogBox.alert("APP表单未配置！");
                return;
            }
            $(document).attr("title", formConfig.sff_title);
            $("#mui-title").text(formConfig.sff_title).css("text-align", "center");
            if (page.isnotNull(formConfig.sff_appjs)) {
                page.loadJsOrCss(formConfig.sff_appjs);
            }
        } else {
            msg = "加载表单配置出错,表单[formCode:" + formCode + "]配置信息不存在";
            mui.alert(msg, '提示', '确定', null, 'div')
            return false;
        }

        return formConfig;
    }

    function initMoreBottom() {
        if (page.checkOtherPlat().isOP) {
            var btnHtml = '<div id="weLinkBtn" class="weLinkBtn"><div class="weLink-Btn"></div></div>';
            $("body").append(btnHtml);
            $(document).on('mousedown', function (e) {
                $('#weLinkBtn').slideUp();
            })
        }
    }

    function initBar() {
        if (page.checkOtherPlat().isOP) {
            var platType = sessionStorage.getItem("_platType");
            if (platType == "DingDing") {
            } else {
                $(".mui-searchRegionS").remove();
                $("#btnHide").remove();
                $(".mui-list-form").css("padding-top", "1px");
            }
        }
    }

    function weLinkMore() {
        if ($("#weLinkBtn").is(":hidden")) {
            $("#weLinkBtn").slideDown()
        } else {
            $("#weLinkBtn").slideUp()
        }
    }

    setTimeout(function (e) {
        initBtns();
        InitForm();
        formOnload();
    }, 10)

</script>


</html>
